<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: products_vpe.php 104 2013-09-21 12:06:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 104 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:06:55 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

define('DEFAULT_PRODUCTS_VPE_ID','1');

require('includes/application_top.php');

switch ($_GET['action']) {
	case 'insert':
	case 'save':
		$products_vpe_id = $_GET['vpe'];

		$languages = get_languages();
		for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			$products_vpe_name_array = $_POST['products_vpe_name'];
			$language_id = $languages[$i]['id'];

			$sql_data_array = array('products_vpe_name' => $products_vpe_name_array[$language_id]);

			if ($_GET['action'] == 'insert') {
				if (!not_null($products_vpe_id)) {
					$next_id = $db->db_query("SELECT MAX(products_vpe_id) AS products_vpe_id FROM ".TABLE_PRODUCTS_VPE);
					$products_vpe_id = $next_id->fields['products_vpe_id'] + 1;
				}

				$insert_sql_data = array('products_vpe_id' => $products_vpe_id, 'language_id' => $language_id);
				$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				$db->db_perform(TABLE_PRODUCTS_VPE, $sql_data_array);

			} elseif ($_GET['action'] == 'save')
				$db->db_perform(TABLE_PRODUCTS_VPE, $sql_data_array, 'update', "products_vpe_id = ".$db->db_prepare($products_vpe_id)." and language_id = '".$language_id."'");
		}

		if ($_POST['default'] == 'on')
			$db->db_query("UPDATE ".TABLE_CONFIGURATION." SET configuration_value = ".$db->db_prepare($products_vpe_id)." WHERE configuration_key = 'DEFAULT_PRODUCTS_VPE_ID'");

		redirect(href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$products_vpe_id));
		break;

	case 'deleteconfirm':
		$vpe = $_GET['vpe'];

		$products_vpe = $db->db_query("SELECT configuration_value from ".TABLE_CONFIGURATION." WHERE configuration_key = 'DEFAULT_PRODUCTS_VPE_ID'");
		if ($products_vpe->fields['configuration_value'] == $vpe)
			$db->db_query("UPDATE ".TABLE_CONFIGURATION." SET configuration_value = '' WHERE configuration_key = 'DEFAULT_PRODUCTS_VPE_ID'");

		$db->db_query("DELETE FROM ".TABLE_PRODUCTS_VPE." WHERE products_vpe_id = ".$db->db_prepare($vpe));

		redirect(href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page']));
	break;

	case 'delete':
		$vpe = $_GET['vpe'];

		$remove_status = true;
		if ($vpe == DEFAULT_PRODUCTS_VPE_ID) {
			$remove_status = false;
			$message_stack->add(ERROR_REMOVE_DEFAULT_PRODUCTS_VPE, 'error');
		}
		break;
}
require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
	</td>
    <td class="boxCenter" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td>
			<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
  				<tr>
    				<td class="pageHeading"><?php echo TABLE_HEADING_PRODUCTS_VPE; ?></td>
  				</tr>
			</table>
		</td>
      </tr>
      <tr>
        <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2" class="dataTable">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_VPE; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
				<?php
				  $products_vpe = $db->db_query("SELECT 
				  									products_vpe_id, 
				  									products_vpe_name 
				  								FROM 
				  									".TABLE_PRODUCTS_VPE." 
				  								WHERE 
				  									language_id = '".$_SESSION['languages_id']."' 
				  								ORDER BY 
				  									products_vpe_id");
				 
				  $rows=1;
				  while (!$products_vpe->EOF) {
				    if (((!$_GET['vpe']) || ($_GET['vpe'] == $products_vpe->fields['products_vpe_id'])) && (!$oInfo) && (substr($_GET['action'], 0, 3) != 'new')) {
				      $oInfo = new objectInfo($products_vpe->fields);
				    }
					if ($i % 2 == 0)
						$f = 'dataTableRow';
					else
						$f = '';
				    if ( (is_object($oInfo)) && ($products_vpe->fields['products_vpe_id'] == $oInfo->products_vpe_id) ) {
				      echo '<tr class="dataTableRowSelected" onmouseover="this.style.cursor=\'pointer\'" onclick="document.location.href=\''.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id.'&action=edit').'\'">'."\n";
				    } else {
				      echo '<tr class="'.$f.'" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'pointer\'" onmouseout="this.className=\''.$f.'\'" onclick="document.location.href=\''.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$products_vpe->fields['products_vpe_id']).'\'">'."\n";
				    }

				    if (DEFAULT_PRODUCTS_VPE_ID == $products_vpe->fields['products_vpe_id']) {
				      echo '<td class="dataTableContent"><b>'.$products_vpe->fields['products_vpe_name'].' ('.TEXT_DEFAULT.')</b></td>'."\n";
				    } else {
				      echo '<td class="dataTableContent">'.$products_vpe->fields['products_vpe_name'].'</td>'."\n";
				    }
				?>
                <td class="dataTableContent" align="right">
					<?php if ( (is_object($oInfo)) && ($products_vpe->fields['products_vpe_id'] == $oInfo->products_vpe_id) ) { echo image(DIR_WS_IMAGES.'icon_arrow_right.gif', ''); } else { echo '<a href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$products_vpe->fields['products_vpe_id']).'">'.image(DIR_WS_IMAGES.'icon_info.gif', IMAGE_ICON_INFO).'</a>'; } ?>&nbsp;</td>
			<?php
				echo '</tr>';
				$rows++;
				$products_vpe->MoveNext();
			  }
			?>
			</table>
			<table width="100%">
              <tr>
                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if (substr($_GET['action'], 0, 3) != 'new') {
?>
                  <tr>
                    <td colspan="2" align="right"><?php echo '<a class="button" onclick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&action=new').'">'.BUTTON_INSERT.'</a>'; ?></td>
                  </tr>
				<?php
				  }
				?>
                </table></td>
              </tr>
            </table></td>
			<?php
			  $heading = array();
			  $contents = array();
			  switch ($_GET['action']) {
			    case 'new':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_NEW_PRODUCTS_VPE.'</b>');

			      $contents = array('form' => draw_form('status', FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&action=insert'));
			      $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);

			      $products_vpe_inputs_string = '';
			      $languages = get_languages();
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $products_vpe_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('products_vpe_name['.$languages[$i]['id'].']');
			      }

			      $contents[] = array('text' => '<br />'.TEXT_INFO_PRODUCTS_VPE_NAME.$products_vpe_inputs_string);
			      $contents[] = array('text' => '<br />'.draw_checkbox_field('default').' '.TEXT_SET_DEFAULT);
			      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'.BUTTON_INSERT.'</button> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page']).'">'.BUTTON_CANCEL.'</a>');
			      break;

			    case 'edit':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_EDIT_PRODUCTS_VPE.'</b>');

			      $contents = array('form' => draw_form('status', FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id .'&action=save'));
			      $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);

			      $products_vpe_inputs_string = '';
			      $languages = get_languages();
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $products_vpe_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('products_vpe_name['.$languages[$i]['id'].']', get_products_vpe_name($oInfo->products_vpe_id, $languages[$i]['id']));
			      }

			      $contents[] = array('text' => '<br />'.TEXT_INFO_PRODUCTS_VPE_NAME.$products_vpe_inputs_string);
			      if (DEFAULT_PRODUCTS_VPE_ID != $oInfo->products_vpe_id) $contents[] = array('text' => '<br />'.draw_checkbox_field('default').' '.TEXT_SET_DEFAULT);
			      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'. BUTTON_UPDATE.'</button> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id).'">'.BUTTON_CANCEL.'</a>');
			      break;

			    case 'delete':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_DELETE_PRODUCTS_VPE.'</b>');

			      $contents = array('form' => draw_form('status', FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id .'&action=deleteconfirm'));
			      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
			      $contents[] = array('text' => '<br /><b>'.$oInfo->products_vpe_name.'</b>');
			      if ($remove_status) $contents[] = array('align' => 'center', 'text' => '<br /><input type="submit" class="button" onClick="this.blur();" value="'.BUTTON_DELETE.'"/> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id).'">'.BUTTON_CANCEL.'</a>');
			      break;

			    default:
			      if (is_object($oInfo)) {

			        $heading[] = array('text' => '<b>'.$oInfo->products_vpe_name.'</b>');

			        $contents[] = array('align' => 'center', 'text' => '<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id.'&action=edit').'">'.BUTTON_EDIT.'</a> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_VPE, 'page='.$_GET['page'].'&vpe='.$oInfo->products_vpe_id.'&action=delete').'">'.BUTTON_DELETE.'</a>');

			        $products_vpe_inputs_string = '';
			        $languages = get_languages();
			        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			          $products_vpe_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.get_products_vpe_name($oInfo->products_vpe_id, $languages[$i]['id']);
			        }

			        $contents[] = array('text' => $products_vpe_inputs_string);
			      }
			      break;
			  }

			  if ( (not_null($heading)) && (not_null($contents)) ) {
			    echo '            <td width="25%" class="border" valign="top">'."\n";

			    $box = new box;
			    echo $box->infoBox($heading, $contents);

			    echo '            </td>'."\n";
			  }
			?>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>